﻿using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using RAD.Modules.UI.Controllers;
using RAD.Modules.UI.Interfaces;
using RAD.Modules.UI.Views;

namespace RAD.Modules.UI
{
    /// <summary>
    /// Модуль UI реализует сборку и взаимодействие с интерфейса
    /// </summary>
    public class UIModule : IModule
    {
        private IUnityContainer _container;
        private IRegionManager _regionManagerService;
        private IEventAggregator _eventAggregator;
        private IAboutViewPresenter _aboutViewPresenter;

        public UIModule(IUnityContainer container, IRegionManager regionManager)
        {
            _container = container;
            _regionManagerService = regionManager;
        }

        #region IModule Members

        public void Initialize()
        {
            RegisterViewsAndServices();

            // Добавляем регион панельи инструментов
            IMainToolBarPresenter presenter = _container.Resolve<IMainToolBarPresenter>();
            _regionManagerService.Regions["MainToolbarRegion"].Add(presenter.View);
        }

        private void RegisterViewsAndServices()
        {
            _container.RegisterType<IMainToolBar, MainToolBar>();
            _container.RegisterType<IMainToolBarPresenter, MainToolBarPresenter>();
            _container.RegisterType<IAboutView, AboutView>();
            _container.RegisterType<IAboutViewPresenter, AboutViewPresenter>();
            _container.RegisterType<IToolbarController, ToolbarController>(new ContainerControlledLifetimeManager());
        }

        #endregion
    }
}